<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>RVM : Compiler Intrinsics</title>
        <link rel="stylesheet" href="styles/site.css" type="text/css" />
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>

    <body>
        <div id="page">
            <div id="main">
                <div id="main-header" class="pageSectionHeader">
                    <h1 id="title-heading" class="pagetitle">
                                                <span id="title-text">
                            RVM : Compiler Intrinsics
                        </span>
                    </h1>

                    <div class="page-metadata">
                        <p>This page last changed on Jul 03, 2008 by <font color="#0050B2">dgrove</font>.</p>
                    </div>
                </div>

                <div id="content" class="view">
                    <div id="main-content" class="wiki-content group">
                    <p>A compiler intrinsic will usually generate a specific code sequence. The code sequence will usually be inlined and optimized as part of compilation phase of the optimizing compiler.</p>

<h2 id="CompilerIntrinsics-Magic">Magic</h2>

<p>All the methods in <code>Magic</code> are compiler intrinsics. Because these methods access raw memory or other machine state, perform unsafe casts, or are operating system calls, they cannot be implemented in Java code.</p>

<p>A Jikes™ RVM implementor must be <em>extremely careful</em> when writing code that uses <code>Magic</code> to circumvent the Java type system.  The use of <code>Magic.objectAsAddress</code> to perform various forms of pointer arithmetic is especially hazardous, since it can result in pointers being &quot;lost&quot; during garbage collection.  All such uses of magic must either occur in uninterruptible methods or be guarded by calls to <code>VM.disableGC</code> and <code>VM.enableGC</code>. The optimizing compiler performs aggressive inlining and code motion, so not explicitly marking such dangerous regions in one of these two manners will lead to disaster.</p>

<p>Since magic is inexpressible in the Java programming language , it is unsurprising that the bodies of <code>Magic</code> methods are undefined. Instead, for each of these methods, the Java instructions to generate the code is stored in <code>GenerateMagic</code> and <code>GenerateMachineSpecificMagic</code> (to generate HIR) and <code>BaselineCompilerImpl</code> (to generate assembly code) (Note: The optimizing compiler always uses the set of instructions that generate HIR; the instructions that generate assembly code are only invoked by the baseline compiler.). Whenever the compiler encounters a call to one of these magic methods, it inlines appropriate code for the magic method into the caller method.</p>
                    </div>

                    
                 
                </div>             </div> 
            <div id="footer" style="background: url(http://docs.codehaus.org/images/border/border_bottom.gif) repeat-x;">
                <p><small>Document generated by Confluence on Feb 17, 2012 10:24</small></p>
            </div>
        </div>     </body>
</html>
